package kuzha.runtime;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import javax.script.Bindings;

import kuzha.KuzhaObject;
import kuzha.runtime.jadapter.ToBindingsAdapter;

public class KzContext extends AbstractContext {
	private Bindings bindings = null;
	
	public KzContext(KuzhaObject _this) {
		super(_this);
	}
	public KzContext(KuzhaObject _this, KuzhaObject _parent) {
		super(_this, _parent);
	}
	public KzContext(KuzhaObject _this, KuzhaObject _super, KuzhaObject _parent) {
		super(_this, _super, _parent);
	}
	
	// javax.script.Bindings /////////////////////////////////
	
	private void PREPARE_BINDINGS() {
		if (bindings == null) {
			bindings = new ToBindingsAdapter(this.table);
		}
	}
	
	public void clear() {
		PREPARE_BINDINGS();
		bindings.clear();
	}
	public boolean containsKey(Object key) {
		PREPARE_BINDINGS();
		return bindings.containsKey(key);
	}
	public boolean containsValue(Object value) {
		PREPARE_BINDINGS();
		return bindings.containsValue(value);
	}
	public Set<Map.Entry<String, Object>> entrySet() {
		PREPARE_BINDINGS();
		return bindings.entrySet();
	}
	public Object get(Object key) {
		PREPARE_BINDINGS();
		return bindings.get(key);
	}
	public boolean isEmpty() {
		PREPARE_BINDINGS();
		return bindings.isEmpty();
	}
	public Set<String> keySet() {
		PREPARE_BINDINGS();
		return bindings.keySet();
	}
	public Object put(String name, Object value) {
		PREPARE_BINDINGS();
		return bindings.put(name, value);
	}
	public void putAll(Map<? extends String, ? extends Object> toMerge) {
		PREPARE_BINDINGS();
		bindings.putAll(toMerge);
	}
	public Object remove(Object key) {
		PREPARE_BINDINGS();
		return bindings.remove(key);
	}
	public int size() {
		PREPARE_BINDINGS();
		return bindings.size();
	}
	public Collection<Object> values() {
		PREPARE_BINDINGS();
		return bindings.values();
	}
}
